package rmiserver;

import java.rmi.*;

import log.Logger;

public class RMIServer extends net.Server {

	public String getName() {
		return "RMIServer";
	}
	
	
	public String getDescription() {
		return "RMI server";
	}
	
	
	public void start() {		
		System.getProperties().put("java.security.policy", "security.policy");
		System.setSecurityManager(new RMISecurityManager());
		try {
			java.rmi.registry.LocateRegistry.createRegistry(1099);
		} catch (RemoteException e1) {
			e1.printStackTrace();
		}
		
		try {
			Naming.rebind("LogonService", new LogonServiceImpl());
			Logger.outputMessage("RMI Server up and running!");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	public void stop() {
		try {
			Naming.unbind("LogonService");
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}
	
	
	public boolean isRunning() {
		try {
			return Naming.lookup("LogonService") != null;
		} catch (Exception e) {
		}
		
		return false;
	}


	public void run() {
		// Do nothing
	}
}
